<template>
	<el-container>
		<el-aside width="220px">
			<el-tree ref="category" class="menu" :default-expand-all="true"
					 node-key="label" :data="category" :default-expanded-keys="['系统日志']" current-node-key="系统日志"
					 :highlight-current="true" :expand-on-click-node="false"
					 @node-click="groupClick">
			</el-tree>
			<el-footer style="height:51px;">
				<el-button type="primary" size="small" icon="el-icon-delete" style="width: 100%;" @click="clearAllBpmRunLog">清除所有日志</el-button>
			</el-footer>
		</el-aside>
		<el-container>
			<el-main class="nopadding">
				<el-container>
					<el-header style="height: auto;">
						<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
					</el-header>
					<el-main class="nopadding">
						<scTable ref="table" :apiObj="apiObj" :params="{date:this.search.date}" stripe highlightCurrentRow @row-click="rowClick">
							<el-table-column label="#" type="index" width="50"></el-table-column>
							<el-table-column label="事件类型" prop="logType" width="100">
								<template #default="scope">
									{{this.getTypeName(scope.row.logType)}}
								</template>
							</el-table-column>
							<el-table-column label="相关流程" prop="flowName" width="150"></el-table-column>
							<el-table-column label="表单名称" prop="formTitle" width="150"></el-table-column>
							<el-table-column label="产生时间" prop="createTime" width="150"></el-table-column>
							<el-table-column label="操作人员" prop="createUserName" width="150"></el-table-column>
							<el-table-column label="事件说明" prop="remark" width="400" :show-overflow-tooltip="true"></el-table-column>
						</scTable>
					</el-main>
				</el-container>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
export default {
	name: 'Bpm Logs',
	components: {scSelectFilter},
	data() {
		return {
			category: [
				{
					label: '日志类型',
					children: [
						{value: '0', label: '发起流程'},
						{value: '1', label: '删除流程'},
						{value: '2', label: '查询流程'},
						{value: '3', label: '表单修改'},
						{value: '4', label: '属性修改'},
						{value: '5', label: '流程回收'},
						{value: '6', label: '流程修改'},
					]
				}
			],
			apiObj: this.$API.bpm.bpmRunLog.getBpmRunLogList,
			flowOptions: [],
			search: {
				keyword: "",
				flowId: '',
				logType:'',
				date: ""
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				}
			],
		}
	},
	mounted() {
		this.getBpmFlowListForSelect()
	},
	methods: {
		filterChange(data){
			this.search.date = data.date;
			this.$refs.table.upData(this.search)
		},
		groupClick(data) {
			this.search.logType = data.value;
			this.$nextTick(() => {
				this.$refs.table.upData(this.search);
			})
		},
		getTypeName(type)
		{
			var resName = "";
			this.category[0].children.forEach(item=>{
				if(type==item.value)
				{
					resName = item.label;
					return;
				}
			})
			return resName;
		},
		async getBpmFlowListForSelect() {
			var res = await this.$API.bpm.bpmFlow.getBpmFlowListForSelect.get({model:'0'});
			if (res.code == 200) {
				this.flowOptions = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async clearAllBpmRunLog()
		{
			var res = await this.$API.bpm.bpmRunLog.clearAllBpmRunLog.post();
			if (res.code == 200) {
				this.$message.success("操作成功");
				this.$refs.table.refresh()
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		upsearch() {
			this.$refs.table.upData(this.search);
		},
		rowClick(row) {
			this.infoDrawer = true
			this.$nextTick(() => {
				this.$refs.info.setData(row)
			})
		}
	}
}
</script>

<style>
</style>
